/** COPYRIGHT(C) 2008. Loc Phan. All Rights Reserved.
    A program that alternatively add and subtract input number
    @author Loc Phan
    @version 1.01 2008-11-11
*/

import java.util.Scanner;

public class ArrayTester
{
   public static void main(String[] args)
   {
      final int ARRAYSIZE = 1000;
      Scanner input = new Scanner(System.in);
      String inputString;
      
      int arrayint[] = new int[ARRAYSIZE];
      int pointer = 0;
      
      System.out.println("Enter an integer or 'c' to compute the sum: ");
      inputString = input.nextLine().toLowerCase();
      
      while(!inputString.contains("c"))
      {
         if (pointer == ARRAYSIZE)
         {
            System.out.println("Input limit exceeded.");
            break;
         }
         try 
         {
            arrayint[pointer] = Integer.parseInt(inputString);
         } 
         catch (Exception e)
         {
            System.out.println("Incorrect input");
            pointer--;
         }
         pointer++;
         System.out.println("Enter an integer or 'c' to compute the sum: ");
         inputString = input.nextLine().toLowerCase();
      }
      
      int sum = 0;

      for(int i=0;i<ARRAYSIZE;i+=2)
      {
         sum+=arrayint[i] - arrayint[i+1];
      }
      
      System.out.println("Sum is "+ sum);
   }
}
